#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct{
	char name[100];
	int age;
	int score;
}student;

int compare(const void *a,const void *b)//
{
	student *s1=(student*)a;
	student *s2=(student*)b;
	if(s1->score!=s2->score)
	{
		return s1->score-s2->score;
	}
	int p=strcmp(s1->name,s2->name);
	if(p!=0)
	{
		return p;
	}
	return s1->age-s2->age;
}

int main()
{
	int n;
	int i,j;
	while(scanf("%d",&n)!=EOF)
	{
		student *students=(student *)malloc(n*sizeof(student));
		if(students==NULL)
		{
			printf("内存分配失败\n");
			return 1;
		}
		for(i=0;i<n;i++)
		{
			scanf("%s %d %d",students[i].name,&students[i].age,&students[i].score);
		}
		qsort(students,n,sizeof(student),compare);
		for(j=0;j<n;j++)
		{
			printf("%s %d %d\n",students[j].name,students[j].age,students[j].score);
		}
		free(students);//
		students=NULL;
	}
	return 0;
}